/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slicktest.entities.ImmobileEntity;

import java.util.List;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import slicktest.entities.Drawable.DrawableEntity;
import slicktest.factories.ImageFactory;
import slicktest.types.DamageType;

/**
 *
 * @author enrightt
 */
public class Tower implements ImmobileEntity, DrawableEntity {

    private double ROF;
    private double damage;
    private double projectileSpeed;
    private double splash;
    private double cost;
    private double buildTime;
    private List<DamageType> damageTypes;
    private String type;
    //use these for upgrading towers - maxUpgrades for how many times you can
    //change it, numUpgrades for how many times it's been changed
    private int maxUpgrades;
    private int numUpgrades;
    //maybe there'll be caltrops, which would be passable, and a tower, which isn't.
    private boolean passable;
    //what types of terrain this tower CAN'T be built on.
    private List<String> restrictions;
    private Image image;
    private float tlx;
    private float tly;

    private boolean[][] footprint;

    public Tower(double ROF,
            double damage,
            double projectileSpeed,
            double splash,
            double cost,
            double buildTime,
            List<DamageType> damageTypes,
            String type,
            int maxUpgrades,
            boolean passable,
            List<String> restrictions,
            boolean[][] footprint,
            String path) throws SlickException {

        this.ROF = ROF;
        this.damage = damage;
        this.projectileSpeed = projectileSpeed;
        this.splash = splash;
        this.cost = cost;
        this.buildTime = buildTime;
        this.damageTypes = damageTypes;
        this.type = type;
        this.maxUpgrades = maxUpgrades;
        this.numUpgrades = 0;
        this.passable = passable;
        this.restrictions = restrictions;
        this.footprint = footprint;
        this.image = ImageFactory.getInstance().getImage(path);
        this.tlx = 0;
        this.tly = 0;
    }

    //copy constructor to make a tower from another one. 
    public Tower(Tower t) {
        this.ROF = t.ROF;
        this.damage = t.damage;
        this.projectileSpeed = t.projectileSpeed;
        this.splash = t.splash;
        this.cost = t.cost;
        this.buildTime = t.buildTime;
        this.damageTypes = t.damageTypes;
        this.type = t.type;
        this.maxUpgrades = t.maxUpgrades;
        this.numUpgrades = 0;
        this.passable = t.passable;
        this.restrictions = t.restrictions;
        this.footprint = t.footprint;
        this.image = t.image;
        this.tlx = 0;
        this.tly = 0;
    }

    public void addUpgrade() {
        numUpgrades++;
    }

    //gives the footprint of terrain a reference to this new tower, and calculates
    //the tower's modified stats given that footprint.
    public void setStatsFromTerrain(List<Terrain> footPrint) {
        //set all of the terrain under this new tower to reference it.
        for (int i = 0; i < footPrint.size(); i++) {
            Terrain t = footPrint.get(i);
            t.setTower(this);

            this.ROF = t.getROF();
            this.damage = t.getDamage();
            this.projectileSpeed = t.getProjectileSpeed();
            this.splash = t.getSplash();
            this.buildTime = t.getBuildTime();
        }
    }

    public double getROF() {
        return ROF;
    }

    public double getDamage() {
        return damage;
    }

    public double getProjectileSpeed() {
        return projectileSpeed;
    }

    public double getSplash() {
        return splash;
    }

    public double getBuildTime() {
        return buildTime;
    }

    public double getCost() {
        return cost;
    }

    public boolean[][] getFootprint() {
        return footprint;
    }

    public List<DamageType> getDamageTypes() {
        return damageTypes;
    }

    public String getType() {
        return type;
    }

    //use this to say when you can't upgrade a tower anymore.
    public boolean isBuildable() {
        return numUpgrades < maxUpgrades;
    }

    //if there are 'towers' you can drop on the walking path, this can be
    //true as well. Caltrops, for example
    public boolean isPassable() {
        return passable;
    }

    public List<String> getRestrictions() {
        return restrictions;
    }

    public void update(GameContainer gc, int delta) throws SlickException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void setX(float x) {
        this.tlx = x;
    }

    public void setY(float y) {
        this.tly = y;
    }

    public void render(GameContainer gc, Graphics graphics) throws SlickException {
        graphics.drawImage(image, tlx, tly);
    }

    @Override
    public String toString() {
        return "Tower{" + "ROF=" + ROF + " damage=" + damage + " projectileSpeed=" + projectileSpeed + " splash=" + splash + " cost=" + cost + " buildTime=" + buildTime + " damageTypes=" + damageTypes + " type=" + type + " maxUpgrades=" + maxUpgrades + " numUpgrades=" + numUpgrades + " passable=" + passable + " restrictions=" + restrictions + '}';
    }
}
